package com.zb.internetSpider.gui;


import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

import com.zb.internetSpider.EntryRun;
import com.zb.internetSpider.bulider.SpiderGuiBuilder;
import com.zb.internetSpider.entity.Menu;
import com.zb.internetSpider.gui.asiderPanel.AbstractSpiderAsiderPanel;
import com.zb.internetSpider.gui.footerBar.AbstractSpiderFooterBar;
import com.zb.internetSpider.gui.frame.AbstractSpiderFrame;
import com.zb.internetSpider.gui.mainPanel.AbstractSpiderMainPanel;
import com.zb.internetSpider.gui.menuBar.AbstractSpiderMenuBar;
import com.zb.internetSpider.gui.splitPanel.AbstractSpiderSplitPane;
import com.zb.internetSpider.gui.tabsPanel.AbstractSpiderTabsPanel;
import com.zb.internetSpider.gui.tree.AbstractSpiderTree;
import com.zb.internetSpider.gui.tree.utils.TreeUtil;
import com.zb.internetSpider.service.api.MenuService;

/**
 * <p> 程序实例创建 </p>
 * @author 张贝
 *
 */
@Component("run")
public class Run {
	
	@Resource
	private Theme theme;
	
	@Resource
	private MenuService menuService;
	
	@Resource
	private SpiderGuiBuilder spiderGuiBuilder;

	/**
	 * 菜单栏
	 */
	@Resource
	private AbstractSpiderMenuBar spiderMenuBar;
	
	/**
	 * 分割面板
	 */
	@Resource
	private AbstractSpiderSplitPane spiderSplitPane;
	
	/**
	 * 页脚
	 */
	@Resource
	private AbstractSpiderFooterBar spiderFooterBar;
	
	/**
	 * 左侧面板
	 */
	@Resource
	private  AbstractSpiderAsiderPanel spiderAsiderPanel;
	
	/**
	 * 右侧面板
	 */
	@Resource
	private  AbstractSpiderMainPanel spiderMainPanel;
	
	/**
	 * 菜单树
	 */
	@Resource
	protected  AbstractSpiderTree spiderTree;
	
	/**
	 * 选项卡面板
	 */
	@Resource
	protected AbstractSpiderTabsPanel spiderTabsPanel;
	
	
	private static ApplicationContext applicationContext = null;
	
	
	public Run() {
		// TODO Auto-generated constructor stub
	}
	
	public static ApplicationContext getApplicationContext() {
		return applicationContext;
	}


	public static void setApplicationContext(ApplicationContext applicationContext) {
		Run.applicationContext = applicationContext;
	}
	
	
	/**
	 * 
	 * @Description: TODO 创建爬虫GUI界面
	 * @param @return   
	 * @return boolean  
	 * @throws
	 * @author zb
	 * @date 2019年2月14日 下午4:29:58
	 */
	public boolean show(){
		boolean state = false;	
		List<Menu> menus = (List<Menu>) TreeUtil.ListToTreeList(menuService.list());
		spiderTree.addMenuData(menus);
		AbstractSpiderFrame frame = this.spiderGuiBuilder.frameBuilder(this.theme, 
				this.spiderTabsPanel,
				this.spiderMainPanel,
				this.spiderAsiderPanel,
				this.spiderSplitPane,
				this.spiderMenuBar, 
				this.spiderFooterBar, 
				this.spiderTree);	
		frame.init();
		frame.create();
		state = true;
		return state;
	}
	
	public boolean initMenu() {
		Menu menu = new Menu();
		menu.setMenuLevel(1);
		menu.setMenuName("菜单管理");
		menu.setMenuParentId(null);
		menu.setMenuSort(1);
		return menuService.save(menu);
	}
	
	

}
